﻿using NFine.Application.SystemSecurity;
using NFine.Code;
using NFine.Domain.Entity.SystemSecurity;
using System.Web.Mvc;

namespace NFine.Web
{
    [HandlerLogin]
    public abstract class ControllerBase : Controller
    {
        public Log FileLog
        {
            get { return LogFactory.GetLogger(this.GetType().ToString()); }
        }
        [HttpGet]
        public virtual ActionResult Index()
        {
            return View();
        }
        [HttpGet]
        public virtual ActionResult Form()
        {
            return View();
        }
        [HttpGet]
        public virtual ActionResult Details()
        {
            return View();
        }
        protected virtual ActionResult Success(string message)
        {
            return Content(new AjaxResult { state = ResultType.success.ToString(), message = message }.ToJson());
        }
        protected virtual ActionResult Success(string message, object data)
        {
            return Content(new AjaxResult { state = ResultType.success.ToString(), message = message, data = data }.ToJson());
        }
        protected virtual ActionResult Error(string message)
        {
            return Content(new AjaxResult { state = ResultType.error.ToString(), message = message }.ToJson());
        }
        /// <summary>
        /// 添加日志
        /// </summary>
        /// <param name="type"></param>
        /// <param name="result"></param>
        /// <param name="desc"></param>
        protected virtual void addLog(string moduleName, string type, bool result, string desc)
        {
            var curUser = OperatorProvider.Provider.GetCurrent();
            LogEntity logEntity = new LogEntity();
            logEntity.F_ModuleName = moduleName;
            logEntity.F_Type = type;
            logEntity.F_Account = curUser.UserCode;
            logEntity.F_NickName = curUser.UserName;
            logEntity.F_Result = result;
            logEntity.F_IPAddress = curUser.LoginIPAddress;
            logEntity.F_IPAddressName = curUser.LoginIPAddressName;
            logEntity.F_Description = desc;
            new LogApp().WriteDbLog(logEntity);
        }
    }
}
